package com.atguigu.day06.Arrays;

/**
 *
 */
public class ArrayTest {
    public static void main(String[] args) {

        //① 一维数组的声明和初始化
        int num;//声明
        num = 10;//初始化
        int id = 1001;//声明 + 初始化

        int[] ids; //声明
        //1.1静态初始化：数组的初始化和数组元素的赋值操作同时进行
        ids = new int[]{1001,1002,1003,1004};
        //1.2动态初始化：数组的初始化和数组元素的赋值操作分开进行
        String[] names = new String[5];

        //错误的写法
//        int[] arr1 = new int[];
//        int[5] arr2 = new int[5];
//        int[] arr3 = new int[3]{1,2,3};

        names[0] = "王明";
        names[1] = "王贺";
        names[2] = "杜明";
        names[3] = "王海";
        names[4] = "张学良";

        //3.如何获取数组的长度
        //属性:length
        System.out.println(names.length);
        System.out.println(ids.length);

        //4.如何遍历数组
        for (int i = 0; i <= names.length-1; i++) {
            System.out.println(names[i]);
        }
    }
}
